package com.application.Adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.application.Activity.R;
import com.application.Adapter.ListChapterAdapter.ViewChapter;

/**
 * 
 * @author h
 *
 */

public class ListChapterAdapter extends ArrayAdapter<ViewChapter>{
	private final Context _context;
	private final ArrayList<ViewChapter> _subContent;
	int _resource;

	/**
	 * @param cContext :truyen activity hien hanh
	 * @param iTextViewResourceId : truyen id widget
	 * @param arrSubject : truyen mang du lieu can load len custom view group
	 */
	public ListChapterAdapter(Context cContext, int iTextViewResourceId, ArrayList<ViewChapter> arrSubject)
	{
		super(cContext,iTextViewResourceId,arrSubject);
		this._context = cContext;
		_resource = iTextViewResourceId;
		_subContent = arrSubject;
	}

	@Override
	public View getView(int iPosition, View vConvertView, ViewGroup vgParent) {
		final ViewChapter vcListChapter = _subContent.get(iPosition);
		
		View vRowView = vConvertView;
		if (vRowView == null) {
			LayoutInflater lInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);;
			vRowView = lInflater.inflate(R.layout.listrow_listchapter,null, true);
		}
		if(vcListChapter !=null)
		{
			//holder = new ViewChatList();			
			TextView tvTitle = (TextView) vRowView.findViewById(R.id.chapter_txt_title);
			TextView tvContent = (TextView) vRowView.findViewById(R.id.chapter_txt_content);
			ImageView img = (ImageView)vRowView.findViewById(R.id.chapter_tv_imgnew);
			
			img.setVisibility(View.INVISIBLE);			
			tvTitle.setText(vcListChapter.sViewTitle);
			tvContent.setText(vcListChapter.sViewContent);
			if(vcListChapter.sStatus == true)
			{	
				img.setImageResource(R.drawable.img_new);
				img.setVisibility(View.VISIBLE);
			}
			
		}
        return vRowView;
	}
	

	public static class ViewChapter{
		public String sViewTitle;
		public String sViewContent;
		public int iViewIdChapter;
		public boolean sStatus;
		
		public ViewChapter(String s1,String s2,int id, boolean status)
		{
			this.sViewTitle = s1;
			this.sViewContent = s2;
			this.iViewIdChapter = id;
			this.sStatus = status;
		}
		
	}
}
